package org.huatek.anders.service;

import com.alibaba.dubbo.config.annotation.Service;
import org.huatek.anders.entity.MqMessageEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.UUID;

/**
 * @author anders
 * @since 2018/11/18 19:43
 */
@Service
@Component
@Slf4j
public class SenderTipsServiceImpl implements  SenderTipsService {

    private final RabbitTemplate rabbitTemplate;
    @Autowired
    public SenderTipsServiceImpl(RabbitTemplate rabbitTemplate){
        this.rabbitTemplate = rabbitTemplate;
    }



    /**
     * 发送消息，不需要实现任何接口，供外部调用
     * @param  mqMessageEntity 消息entity
     */
    @Override
    public void send(MqMessageEntity mqMessageEntity) {
        CorrelationData correlationId = new CorrelationData(UUID.randomUUID().toString());
        rabbitTemplate.convertAndSend(mqMessageEntity.getRoutingKey(), mqMessageEntity, correlationId);
    }

}
